package com.restaurant.application.minifacade.data;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;
import java.util.stream.Collectors;

public class ShopGoodsBO implements PickableBean {

    public static final String FN_SHOPID = "shopId";
    public static final String FN_SHOPNAME = "shopName";
    public static final String FN_TYPES = "types";
    public static final String FN_GOODS = "goods";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_SHOPID,
            FN_SHOPNAME,
            FN_TYPES,
            FN_GOODS);

    private String shopId;
    private String shopName;
    private List<TypeBO> types;
    private List<GoodsBO> goods;

    public ShopGoodsBO(String shopId, String shopName, List<TypeBO> types, List<GoodsBO> goods) {
        setShopId(shopId);
        setShopName(shopName);
        setTypes(types);
        setGoods(goods);
    }

    public ShopGoodsBO() {
    }

    public ShopGoodsBO duplicate() {
        ShopGoodsBO result = new ShopGoodsBO();
        result.shopId = this.shopId;
        result.shopName = this.shopName;
        result.types = this.types == null ? null : this.types.stream().map(e1 -> e1 == null ? null : e1.duplicate()).collect(Collectors.toList());
        result.goods = this.goods == null ? null : this.goods.stream().map(e2 -> e2 == null ? null : e2.duplicate()).collect(Collectors.toList());
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getShopId() {
        return shopId;
    }

    public void setShopId(String value) {
        this.shopId = value;
    }

    public ShopGoodsBO withShopId(String value) {
        setShopId(value);
        return this;
    }

    public ShopGoodsBO withShopId(String value, String defaultValue) {
        setShopId(value == null ? defaultValue : value);
        return this;
    }

    public String getShopName() {
        return shopName;
    }

    public void setShopName(String value) {
        this.shopName = value;
    }

    public ShopGoodsBO withShopName(String value) {
        setShopName(value);
        return this;
    }

    public ShopGoodsBO withShopName(String value, String defaultValue) {
        setShopName(value == null ? defaultValue : value);
        return this;
    }

    public List<TypeBO> getTypes() {
        if (types == null) {
            types = Lists.newArrayList();
        }
        return types;
    }

    public void setTypes(List<TypeBO> value) {
        this.types = value;
    }

    public ShopGoodsBO withTypes(List<TypeBO> value) {
        setTypes(value);
        return this;
    }

    public ShopGoodsBO withTypes(List<TypeBO> value, List<TypeBO> defaultValue) {
        setTypes(value == null ? defaultValue : value);
        return this;
    }

    public ShopGoodsBO addTypes(TypeBO value) {
        if (types == null) {
            types = Lists.newArrayList();
        }
        this.types.add(value);
        return this;
    }

    public List<GoodsBO> getGoods() {
        if (goods == null) {
            goods = Lists.newArrayList();
        }
        return goods;
    }

    public void setGoods(List<GoodsBO> value) {
        this.goods = value;
    }

    public ShopGoodsBO withGoods(List<GoodsBO> value) {
        setGoods(value);
        return this;
    }

    public ShopGoodsBO withGoods(List<GoodsBO> value, List<GoodsBO> defaultValue) {
        setGoods(value == null ? defaultValue : value);
        return this;
    }

    public ShopGoodsBO addGoods(GoodsBO value) {
        if (goods == null) {
            goods = Lists.newArrayList();
        }
        this.goods.add(value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "shopId":
                return getShopId();
            case "shopName":
                return getShopName();
            case "types":
                return getTypes();
            case "goods":
                return getGoods();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof ShopGoodsBO)) return false;
        return signature().equals(((ShopGoodsBO) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean ShopGoodsBO has no signature defined, no hash code or equals possible.");
    }
}
